<%@ page contentType="text/html;charset=utf-8"%>
<%@page import="com.leruan.aasimp.util.DateUtils"%>
<%@page import="com.leruan.aasimp.util.StringUtil"%>
<%@page import="com.leruan.aasimp.util.StringUtils"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@page import="com.leruan.aasimp.entity.Board"%>
<%@page import="com.leruan.aasimp.entity.Mainpost"%>
<%@page import="com.leruan.aasimp.entity.Forumuser"%>
<%@ page import="java.util.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
		//User user = new User(11,"测试用户1","fdsfd",3,"dfsafdsf",4321432);
		//request.getSession().setAttribute("user",user);
Forumuser user = (Forumuser)request.getSession().getAttribute("user");
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE></TITLE>
<LINK href="styles/green/ejforum.css" type=text/css rel=stylesheet>
<SCRIPT src="js/common.js" type=text/javascript></SCRIPT>
<SCRIPT src="js/md5.js" type=text/javascript></SCRIPT>
<SCRIPT type=text/javascript>
function checkfield(theform) {
	if(trim($('username').value) == '') {
		alert('用户名不可以为空');return false;
	} else if(trim($('password1').value) == '') {
		alert('密码不可以为空');return false;
	} else {
		$('password').value = hex_md5(trim($('password1').value)); 
		$('password1').value = '';
		theform.submit();return false;
	}
}
function toRegister(){
	window.location.href="toRegister";
}
function doSearch() {
	if(trim($('frmsearch').q.value)=='')
	{
		alert('请输入搜索关键字');
		return false;
	}
	frmsearch.submit();
}
function newPost(boardId){
	if(<%=user==null%>){
			if(confirm("请先登录！")){
				document.location.href="loginOnly";
			}
		}else{
				window.location.href="newPost?boardId="+boardId;
			}
}
</SCRIPT>
</HEAD>
<BODY onkeydown="if(event.keyCode==27) return false;">
<DIV class="wrap">
<s:actionerror cssStyle="color:red"/>
	<table>
		<tr>
			<td >
			     <div style="height:73px; width: 193px; background-image: url('images/forumlogo.jpg')"></div>
			</td>
			<td align="right" width="1000%">
				<DIV id=foruminfo>
				<%if(null==user){
				%>
				<form action="login" onSubmit="checkfield(this); return false;" method="get">
				用户名：<input type=text id="username" name="username" size=13 maxlength=30 tabindex=1/>
				密码：<input type=password id="password1" name="password1" size=8 tabindex=2 onkeypress="if((event.keyCode?event.keyCode:event.charCode)==13) $('loginform').submit();"/>
				<INPUT type=hidden id="password" name="password">&nbsp;
				<button type="submit" name=loginsubmit tabIndex=3 style="width:46px">登录</button>
				<button type="button" name="register" tabIndex=3 style="width:46px" onclick="toRegister()">注册</button></form>
				<%
				} else{
				%>
				欢迎您! <a href="userDetails?username=<%=user.getUsername() %>&userId=<%=user.getUserId() %>"><%=user.getUsername() %></a> <a href="logout.action">退出登录</a>
				<%
				}%>
				</DIV>
			</td>
		</tr>
	</table>
<DIV class="mainbox forumlist" style="padding-top:0px">
<H1>乐软汽车论坛</H1>
<TABLE cellSpacing=0 cellPadding=0>
  <THEAD class=category>
  <TR>
	  <TD style="padding-bottom: 1px" 
			align=center>≡&nbsp;最新发表&nbsp;≡</TD>
	  <TD style="padding-bottom: 1px" 
			align=center>≡&nbsp;热门主题&nbsp;≡</TD>
	  <TD style="padding-bottom: 1px" 
			align=center>≡&nbsp;最新精华&nbsp;≡</TD>
  </TR>
  <tr>
  	<td align="center">
	  	<div>
	  		<%
	  		int i=0;
	  		List<Mainpost> newMainPosts = (List<Mainpost>)request.getAttribute("newMainPosts");
			for(Mainpost b:newMainPosts){
			if(i<5){
			%>
				<IMG alt="置顶" src="images/item.gif">&nbsp;<a href="viewPost?postId=<%=b.getPostId() %>" target="blank" title="<%=b.getPostTitle() %>"><%=StringUtils.cutOff(b.getPostTitle(),10,"...") %></a> 发表日期： <%=DateUtils.date2StringBySecond(b.getPostDate()) %><br/>
			<%
			i++;
			}
			}
	  		%>
	  	</div>
  	</td>
  	<td align=center>
  		<div>
  		  	<%
  		  	int j=0;
	  		List<Mainpost> popularMainPosts = (List<Mainpost>)request.getAttribute("popularMainPosts");
			for(Mainpost b:popularMainPosts){
			if(j<5){
			if(j<3){
			%>
				<IMG alt="置顶" src="images/top_<%=j%>.gif"><%}else{ %>&nbsp;<%} %><a href="viewPost?postId=<%=b.getPostId() %>" target="blank" title="<%=b.getPostTitle() %>"><%=StringUtils.cutOff(b.getPostTitle(),10,"...") %></a>  回复：<%=b.getReplyNum() %> 点击：<%=b.getHits() %><br/>
			<%
			j++;
			}
			}
	  		%>	
  		</div>
  	</td>
  	<td align=center>
  		<div>
  		  	<%
  		  	int k=0;
	  		List<Mainpost> newEssenceMainPosts = (List<Mainpost>)request.getAttribute("newEssenceMainPosts");
			for(Mainpost b:newEssenceMainPosts){
			if(k<5){
			%>
				<IMG alt="精华" src="images/digest.gif">&nbsp;<a href="viewPost?postId=<%=b.getPostId() %>" target="blank" title="<%=b.getPostTitle() %>" ><%=StringUtils.cutOff(b.getPostTitle(),10,"...")%></a>  回复：<%=b.getReplyNum() %> 点击：<%=b.getHits() %><br/>
			<%
			k++;
			}
			}
	  		%>	
  		</div>
  	</td>
  </tr>
  </THEAD>
  <TBODY>
  <TR>
  </TR></TBODY></TABLE></DIV>
<DIV class="mainbox forumlist">
<H1>板块
<SPAN class=headactions><IMG id=section__img title="收起/展开" onClick="toggle_collapse('section_');"
		alt="收起/展开" src="styles/green/images/collapsed_no.gif"></SPAN>
</H1>
<TABLE id="section_" cellSpacing=0 cellPadding=0>
  <THEAD class=category>
	  <TR>
	    <TH>版块</TH>
	    <TH class=nums>版主</TH>
	    <TH class=nums>帖数</TH>
	    <TH class=lastpost>点击数</TH>
	  </TR>
  </THEAD>
  <TBODY>
  <%
   Map<String,Forumuser> forumuserMap = (Map<String,Forumuser>)request.getAttribute("forumuserMap");
   List<Board> boards = (List<Board>)request.getAttribute("boards");
   for(Board b:boards){%>
	  <TR>
		  <TH><p><a href="boardPostList?boardId=<%=b.getBoardId() %>" target="blank">版块:<%=b.getBoardName() %></a></p></TH>
	      <TH><P>版主:<%=null==forumuserMap.get(b.getBoardUserId())?"本版暂无版主":forumuserMap.get(b.getBoardUserId()).getUsername() %></P></TH>
	      <TH><P>帖数:<%=b.getPostNum() %></P></TH>
	      <TH><P>点击数:<%=b.getHits() %> </P></TH>
	      <TH><a href="javascript:newPost('<%=b.getBoardId() %>')" target="_blank"><P>发帖</P></a> </TH>
	  </TR>
   <%
   }
   %>
  </TBODY>
</TABLE></DIV>
<DIV class=box><SPAN class=headactions><IMG id=forumlinks_img 
onclick="toggle_collapse('forumlinks');" src="styles/green/images/collapsed_no.gif"></SPAN> 

<DIV class="box" id="online">
<H4><strong>在线会员</strong>&nbsp;&nbsp;-&nbsp;&nbsp;共&nbsp;<EM></EM> 人在线，其中会员&nbsp;<EM></EM> 人&nbsp;-&nbsp;&nbsp;最高记录是&nbsp;<EM></EM>&nbsp; 于&nbsp;<EM></EM>
</H4>
</DIV>
<DIV class=legend>
Design By:<a href="index.jsp">乐软</a>
<LABEL>
<IMG alt="论坛后台" align="absmiddle" src="styles/green/images/forum_new.gif"><a href="loginAdmin">论坛后台</a>
</LABEL> 
</BODY></HTML>
